// pages/fillpassword/fillpassword.js
const app  = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    password:'',
    new_password:'',
    confirm_password:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu({
      complete: (res) => {},
    })
    this.getData();
  },
  getData : function(){
  },
  inputNewPassword: function(e){
    this.setData({
      new_password:e.detail.value
    })
    if(this.data.new_password != this.data.confirm_password){
      wx.showToast({
        title: '两次输入密码不一致',
      })
    }
  },
  inputConfirmPassword: function(e){
    this.setData({
      confirm_password:e.detail.value
    })
    if(this.data.new_password != this.data.confirm_password){
      wx.showToast({
        title: '两次输入密码不一致',
      })
    }
  },
  inputPassword: function(e){
    this.setData({
      password:e.detail.value
    })
  },
  tapSubmit: function(){
    var context = this;
    console.log(this.data.new_password,this.data.new_password.length);
    if(this.data.new_password.length < 6){
      wx.showToast({
        title: '密码长度不能小于6个字符',
      })
      return false;
    }
    wx.request({
      url: app.config.server + "/api/update_password",
      method:'POST',
      data:{
        password:this.data.password,
        new_password:this.data.new_password
      },
      header:{
        sesssionkey : wx.getStorageSync('session_key')
      },
      success: res => {
        console.log(res);
        context.setData({
          password: context.data.new_password
        });
        wx.navigateTo({
          url:'/pages/personal/personal',
          complete: (res) => {
            wx.showToast({
              title:'修改密码成功'     
           })
          },
        })
      }
    })
  }
})